package com.yugu.park.business.controller;

import com.github.pagehelper.PageInfo;
import com.yugu.enums.BusinessType;
import com.yugu.park.annotation.Log;
import com.yugu.park.business.entity.AdmissionRecord;
import com.yugu.park.business.service.AdmissionRecordService;
import com.yugu.park.dto.AdmissionRecordDto;
import com.yugu.util.ResponseUtil;
import com.yugu.util.SearchPage;
import com.yugu.util.SysQueryParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * @author Noble-Six
 * @date 2024/4/25
 */
@RestController
@Api(tags = "入园记录信息")
@RequestMapping("/business/admissionRecord")
public class AdmissionRecordController {

    @Resource
    private AdmissionRecordService admissionRecordService;

    @ApiOperation(value = "新增修改入园记录信息")
    @PostMapping("/addOrUpdate")
    @Log(title ="新增修改入园记录信息" ,businessType = BusinessType.UPDATE)
    public ResponseUtil.Result<Boolean> addOrUpdate(@RequestBody AdmissionRecord record){
        admissionRecordService.addOrUpdate(record);
        return ResponseUtil.addSuccess(true);
    }

    @ApiOperation(value="分页查询", notes="分页查询")
    @PostMapping(value = "/page")
    public ResponseUtil.Result<PageInfo<AdmissionRecordDto>> page (@RequestBody SearchPage<SysQueryParam> search){
        PageInfo<AdmissionRecordDto> page = admissionRecordService.page(search);
        return ResponseUtil.addSuccess(page);
    }

    @ApiOperation(value="批量删除", notes="批量删除")
    @DeleteMapping(value="/{id}")
    @Log(title ="删除入园记录信息" ,businessType = BusinessType.DELETE)
    @Transactional(rollbackFor = Exception.class)
    public ResponseUtil.Result<Boolean> delete(@PathVariable("id") String id){
        admissionRecordService.removeByIds(Arrays.asList(id.split(",")));
        return ResponseUtil.addSuccess(true);
    }
}
